﻿
using mds.Queue.MSMQServer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceProcess;
using System.Text;

namespace mds.Queue
{
   public class MSMQService
    {
       private MSMQServiceFactory _serviceFactory;
       public MSMQService()
       {
           _serviceFactory = new MSMQServiceFactory();
       }
       public void Run(string[] args)
       {
           if (null != args && args.Length > 0 && args[0].ToLower() == "/console")
           {
               //以控制台模式启动
               IMSMQProcess defaultProcessService = _serviceFactory.CreateDefaultProcessService();
               if (defaultProcessService != null)
               {
                   defaultProcessService.OnConsoleStart(args);
                   Console.Read();
               }
               else
               {
                   Console.WriteLine("服务生成失败，请检查配置ServiceConfig配置节是否正确，引用文件是否正确");
               }
           }
           else
           {
               var serviceGroup = _serviceFactory.CreateServiceGroup();
               if(serviceGroup!=null)
               ServiceBase.Run(serviceGroup);
           }
       }
    }
}
